package com.andyage.admin.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.andyage.admin.service.IAdProjectService;
import com.andyage.util.DateUtil;
import com.andyage.util.GetUUID;
import com.andyage.admin.bean.AdprojectBean;

@Controller
@RequestMapping("/admin")
public class AdProjectAction {
	@Resource
	private IAdProjectService iadprojectService;
	@RequestMapping("/queryAdProject")
	public void queryAdProject(HttpServletRequest request, HttpServletResponse response,AdprojectBean adProject){
		try {
			iadprojectService.queryAdProject(request, response, adProject);
		} catch (Exception e) {
			e.printStackTrace();
		};
	}
	@RequestMapping("/addAdProject")
	public void addAdProject(HttpServletRequest request, HttpServletResponse response,AdprojectBean adProject){
		try {
			adProject.setProjectId(GetUUID.get());
			String startTime=request.getParameter("StartTime");
			if(startTime!=null&&!startTime.equals(""))
			adProject.setProjectStartTime(DateUtil.getDate(startTime));
			String endTime=request.getParameter("EndTime");
			if(endTime!=null &&!endTime.equals("")){
				adProject.setProjectEndTime(DateUtil.getDate(endTime));
			}
			adProject.setProjectStatus(0);
			iadprojectService.addAdProject(request, response, adProject);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping("/updateAdProject")
	public void updateAdProject(HttpServletRequest request, HttpServletResponse response,AdprojectBean adProject) {
		try {
			String startTime=request.getParameter("StartTime");
			if(startTime!=null&&!startTime.equals(""))
			adProject.setProjectStartTime(DateUtil.getDate(startTime));
			String endTime=request.getParameter("EndTime");
			if(endTime!=null &&!endTime.equals("")){
				adProject.setProjectEndTime(DateUtil.getDate(endTime));
			}
			String projectId=request.getParameter("projectId");
			adProject.setProjectId(projectId);
			iadprojectService.updateAdProject(request, response, adProject);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping("/deleteAdProject")
	public  void deleteAdProject(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			iadprojectService.deleteAdProject(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping("/updateProjectPublish")
	public  void updateProjectPublish(HttpServletResponse response,AdprojectBean adProject,HttpServletRequest request) {
		try {
			iadprojectService.updateProjectPublish(adProject,response,request);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	@RequestMapping("/queryProjectByStatus")
	public  void queryProjectByStatus(HttpServletResponse response,AdprojectBean adProject) {
		try {
			iadprojectService.queryProjectByStatus(adProject, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping("/updateProjectByProjectStatus")
	public  void updateProjectByProjectStatus(HttpServletRequest request,AdprojectBean adProject,HttpServletResponse response) {
		try {
			iadprojectService.updateProjectByProjectStatus(request,adProject, response);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
